import request from '@/utils/request'
import type {
  UserResponseData,
  User,
  RoleResponseData,
  SetRoleData,
} from './type'
//用户管理模块相关接口

//获取所有用户接口
export const reqAllUserAPI = (page: number, limit: number, username: string) =>
  request.get<any, UserResponseData>(
    `/admin/acl/user/${page}/${limit}/?username=${username}`
  )
//添加或者修改用户账号
export const reqAddOrUpdateUserAPI = (data: User) => {
  if (data.id) {
    return request.put<any, any>('/admin/acl/user/update', data)
  } else {
    return request.post<any, any>('/admin/acl/user/save', data)
  }
}
//获取用户职位接口
export const reqGetRoleListAPI = (userId: number) =>
  request.get<any, any>(`/admin/acl/user/toAssign/${userId}`)
//修改用户职位接口
export const reqUpdateRoleListAPI = (data: SetRoleData) =>
  request.post<any, any>(`/admin/acl/user/doAssignRole`, data)
//删除用户账号
export const reqDeleteUserAPI = (id: number) =>
  request.delete<any, RoleResponseData>(`/admin/acl/user/remove/${id}`)
//批量删除用户账号
export const reqBatchDeleteUserAPI = (idsList: number[]) =>
  request.delete<any, RoleResponseData>(`/admin/acl/user/batchRemove`, {
    data: idsList,
  })
